<script lang="ts" setup>
import {
  UserOutlined,
  LeftCircleOutlined,
  RightCircleOutlined,
  DownOutlined,
  ArrowRightOutlined,
  FileDoneOutlined,
  DollarOutlined,
  AlipayCircleOutlined

} from "@ant-design/icons-vue";
import { reactive, ref, h } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const value = ref<string>("名称");
const searchValue = ref<string>("");
const isShowList = ref<boolean>(false);

const listCard = reactive([
  {
    auther: "艺人名称",
    userId: 12,
    worksList: [
      {
        id: 1,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 2,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 3,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 4,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 5,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 6,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
    ],
  },
  {
    auther: "艺人名称123",
    userId: 112,
    worksList: [
      {
        id: 1,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 2,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 3,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 4,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 5,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 6,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
    ],
  },
  {
    auther: "艺人名称123",
    userId: 1112,
    worksList: [
      {
        id: 1,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 2,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
      {
        id: 3,
        img: "https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_640.jpg",
        title: "专辑1",
        text: "这是内容内容内容内容内容内容内容内容内容",
      },
    ],
  },
]);

interface DataItem {
  title: string;
}
const data: DataItem[] = [
  {
    title: "Ant Design Title 1",
  },
  {
    title: "Ant Design Title 2",
  },
  {
    title: "Ant Design Title 3",
  },
  {
    title: "Ant Design Title 4",
  },
];
const onSearch = () => { };

const handleFocus = () => {
  // console.log('获取焦点');
  isShowList.value = true;
};

const handleBlur = () => {
  // console.log('失去焦点');
  isShowList.value = false;
};

const logIn = () => {
  router.push({ path: "/login" });
  // console.log(router);
};

const myResources = () => {
  router.push({ path: "/myresources" });
};
const publishingResources = () => {
  router.push({ path: "/publishingresources" });
};
const checkAll = () => {
  router.push({ path: "/AllResources" });
}
const gotoWithdrawal = () => {
  router.push({ path: "/withdrawal" });
}

const gotoRecharge = () => {
  router.push({ path: "/withdrawal" });
}
</script>


<template>
  <div class="home_page">

    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-light bg-body-tertiary sticky-md-top mb-1">
      <!-- Container wrapper -->
      <div class="container-fluid">

        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
          aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <!-- Collapsible wrapper -->
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Navbar brand -->
          <a class="navbar-brand mt-2 mt-lg-0" href="#">
            LOGO
          </a>
          <ul class="navbar-nav me-auto mb-2 mb-lg-0">
            <li class="nav-item" style="width: 30%;">
              <a class="nav-link" @click="myResources">我的资源</a>
            </li>
            <li class="nav-item" style="width: 30%;">
              <a class="nav-link" @click="publishingResources">发布资源</a>
            </li>
            <li class="nav-item" style="width: 100%;">
              <div class="search_box" role="search">
                <a-input size="large" v-model:value="searchValue" placeholder="请输入关键字" enter-button @search="onSearch"
                  @blur="handleBlur" @focus="handleFocus">
                  <template #addonBefore>
                    <a-space>
                      <a-select ref="select" v-model:value="value" style="width: 120px" size="large">
                        <a-select-option value="名称">名称</a-select-option>
                        <a-select-option value="描述">描述</a-select-option>
                      </a-select>
                    </a-space>
                  </template>
                </a-input>

                <div class="list_proposal" v-show="isShowList">
                  <div class="record">
                    <div class="title">历史搜索</div>
                    <div class="record_list">
                      <a-list item-layout="horizontal" :data-source="data">
                        <template #renderItem="{ item }">
                          <a-list-item>
                            {{ item.title }}
                          </a-list-item>
                        </template>
                      </a-list>
                    </div>
                  </div>
                </div>
              </div>
            </li>
          </ul>

        </div>
        <!-- 个人操作 -->
        <div class="d-flex">
          <!-- <a-button class="d-flex justify-content-center align-items-center" type="text">提现<FileDoneOutlined /></a-button>
            <a-button class="d-flex justify-content-center align-items-center" type="text">充值<FileDoneOutlined /></a-button>
            <a-button class="d-flex justify-content-center align-items-center" type="text">订单<FileDoneOutlined /></a-button> -->
          <a-dropdown>
            <template #overlay>
              <a-menu>
                <a-menu-item key="1">
             
                  <a-button class="d-flex justify-content-center align-items-center" type="text" @click="gotoWithdrawal">
                    <DollarOutlined class="ml-2" />
                    提现
                  </a-button>
                </a-menu-item>
                <a-menu-item key="2">

                  <a-button class="d-flex justify-content-center align-items-center" type="text" @click="gotoRecharge">
                    <AlipayCircleOutlined class="ml-2" />
                    充值
                  </a-button>
                </a-menu-item>

              </a-menu>
            </template>
            <a-button type="text">
              订单
              <DownOutlined />
            </a-button>
          </a-dropdown>
          <a-button class="d-flex justify-content-center align-items-center" type="text" @click="logIn">去登录
            <UserOutlined class="ml-2" />
          </a-button>

        </div>
      </div>
    </nav>
    <!-- Navbar -->
    <!-- <div style="height: 200px;"> -->
    <a-carousel class="h-50" arrows>
      <template #prevArrow>
        <div class="custom-slick-arrow" style="left: 10px; z-index: 1">
          <LeftCircleOutlined />
        </div>
      </template>
      <template #nextArrow>
        <div class="custom-slick-arrow" style="right: 10px">
          <right-circle-outlined />
        </div>
      </template>
      <img src="https://pic1.zhimg.com/v2-f672a345fd1382a1c2954741ccd5a75d_r.jpg" v-for="item in 4" :key="item" class=""
        alt="..." />

    </a-carousel>
    <!-- </div> -->
    <div class="resource_list">
      <div class="" v-for="(item, index) of listCard" :key="item.userId">
        <div class="d-flex justify-content-between align-items-center">
          <div>{{ item.auther }}</div>
          <a-button shape="round"  class="d-flex justify-content-between align-items-center" @click="checkAll">
            查看全部
            <ArrowRightOutlined style="vertical-align: -50%" />
          </a-button>



        </div>

        <div class="row">
          <div class="col-sm-3 " v-for="(childrenItem, childrenIndex) of item.worksList">
            <div class="card my-3 card_box">
              <div>
                <img :src="childrenItem.img" class="card-img-top img-fluid" alt="..." />
              </div>
              <div class="card-body">
                <h5 class="card-title">{{ childrenItem.title  }}</h5>
                <p class="card-text card_text">{{ childrenItem.text  }}</p>
                <!-- <a href="#" class="btn btn-primary" data-mdb-ripple-init>Go somewhere</a> -->
              </div>
              <div class="card-footer">
                <small class="text-body-secondary">下载次数： 1000</small>
              </div>
            </div>
          </div>

        </div>

      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card_box {
  cursor: pointer;
  transition: all .2s;

  &:hover {
    transform: translateY(-5px);
    box-shadow: 2px 2px 2px #eee;
    // border: 1px solid #1677ff;
  }

  .card_text {

    width: auto;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

:deep(.slick-slide) {
  text-align: center;
  height: 230px;
  line-height: 230px;
  background: #364d79;
  overflow: hidden;

  img {
    width: 100%;
    height: 230px;
  }
}

:deep(.slick-arrow.custom-slick-arrow) {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  transition: ease all 0.3s;
  opacity: 0.3;
  z-index: 1;
}

:deep(.slick-arrow.custom-slick-arrow:before) {
  display: none;
}

:deep(.slick-arrow.custom-slick-arrow:hover) {
  color: #fff;
  opacity: 0.5;
}

:deep(.slick-slide h3) {
  color: #fff;
}

.home_page {
  max-width: 1200px;
  margin: 0 auto;

  .resource_list {
    margin-top: 20px;
  }
}


.search_box {
  width: 100%;
  position: relative;
  height: 40px;

  // background-color: antiquewhite;
  .list_proposal {
    position: absolute;
    width: 100%;
    // bottom: -40px;
    padding: 10px 30px;
    top: 40px;
    box-sizing: border-box;
    z-index: 99;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 1px 6px 6px -1px #c7c7c7;

    .record {
      .title {
        color: #c7c7c7;
        font-size: 12px;
      }

      .record_list {
        max-height: 350px;
        overflow-y: scroll;
      }
    }
  }
}
</style>